package cn.rongdao.jrkabao.dao;

import com.mifengkong.frtools.util.FRString;
import com.mifengkong.greendao.bean.UserInfo;

import java.util.List;


/**
 * Created by jack on 2017/8/26
 */

public class UserDao extends BaseDao<UserInfo> {

    public static UserDao getInstance() {
        return getPresent(UserDao.class);
    }

    public boolean isUserLogin() {
        return !FRString.isEmpty(getUserId());
    }

    private UserInfo getUserInfo() {
        List<UserInfo> userInfoList = queryAll(UserInfo.class);
        if (null != userInfoList && userInfoList.size() > 0) {
            return userInfoList.get(0);
        }
        return null;
    }

    public String getUserId() {
        if (null != getUserInfo()) {
            return FRString.valueOf(getUserInfo().getUser_id());
        }
        return FRString.EMPTY_STRING;
    }

    public String getToken() {
        if (null != getUserInfo()) {
            return FRString.valueOf(getUserInfo().getToken());
        }
        return FRString.EMPTY_STRING;
    }

    public String getPhone() {
        if (null != getUserInfo()) {
            return FRString.valueOf(getUserInfo().getPhone());
        }
        return FRString.EMPTY_STRING;
    }

    public void deleteUser() {
        if (!FRString.isEmpty(getUserId())) {
            UserInfo userInfo = getUserInfo();
            if (null != userInfo) {
                deleteObject(userInfo);
            }
        }
    }
}